#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int process(vector<vector<int>> &grid, int i, int j)
{
    if (i < 0 || i >= grid.size())
    {
        return 0;
    }
    if (j < 0 || j >= grid[i].size())
    {
        return 0;
    }
    if (grid[i][j] == 1)
    {
        grid[i][j] = 0;
        return 1 + process(grid, i + 1, j) + process(grid, i - 1, j) + process(grid, i, j + 1) + process(grid, i, j - 1);
    }
    else
    {
        return 0;
    }
}

int _695(vector<vector<int>> &grid)
{
    int m = grid.size();
    int n = grid[0].size();
    int MaxArea = 0;
    int area;
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (grid[i][j] == 1)
            {
                area = process(grid, i, j);
                MaxArea = max(MaxArea, area);
            }
        }
    }
    return MaxArea;
}

int main()
{
    vector<vector<int>> grid = {{1, 0, 1, 1, 0, 1, 0, 1}, {1, 0, 1, 1, 0, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1}};
    cout << _695(grid) << flush;
    return 0;
}